package ex03;

import ex02.Constants;
import ex03.connector.http.HttpRequest;
import ex03.connector.http.HttpResponse;

import javax.servlet.Servlet;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandler;

/**
 * @packgeName: ex03.connector
 * @ClassName: ServletProcessor
 * @copyright: CopyLeft
 * @description:<描述>
 * @author: lili
 * @date: 2017/8/11-18:45
 * @version: 1.0
 * @since: JDK 1.8
 */
public class ServletProcessor {
    public void process(HttpRequest request, HttpResponse response){

        String uri = request.getRequestURI();
        String servletName = uri.substring(uri.indexOf("/")+1);
        URLClassLoader loader = null;

        try{
            URL[] urls = new URL[1];
            URLStreamHandler streamHandler = null;
            File classPath = new File(Constants.WEB_ROOT);
            String repository = (new URL("file",
                    null,
                    classPath.getCanonicalPath() + File.separator)
            ).toString() ;
            urls[0] = new URL(null, repository, streamHandler);
            loader = new URLClassLoader(urls);

        }catch (IOException e){
            System.out.println(e.toString());
        }

        Servlet servlet = null;

        // TODO: 2017/8/29  写到这里了

    }
}
